package com.ruoyi.config;

import com.ruoyi.platform.constant.MqConstants;
import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: lzx
 * @Date: 2022/11/07/14:27
 * @Description:
 **/
@Configuration(proxyBeanMethods = false)
public class RabbitMqConfig {

    /**
     * 消息序列化设置
     *
     * @return
     */
    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }


    /**
     * 日志的队列
     *
     * @return
     */
    @Bean
    public Queue logQueue() {
        return new Queue(MqConstants.LOG_QUEUE_NAME, true, false, false);
    }


    /**
     * 创建日志交换机
     *
     * @return
     */
    @Bean
    public Exchange logEventChange() {
        return new DirectExchange(MqConstants.LOG_EVENT_EXCHANGE, true, false);
    }


    /**
     * 日志队列绑定
     *
     * @return
     */
    @Bean
    public Binding logBinding() {
        return new Binding(MqConstants.LOG_QUEUE_NAME, Binding.DestinationType.QUEUE, MqConstants.LOG_EVENT_EXCHANGE,
                MqConstants.LOG_KEY_NAME, null);
    }


}
